Welcome to Css!

第七章:背景属性

7.01 背景颜色

background-color:合法的颜色值

1、 合法的颜色值:颜色名,16进制颜色值,rgb颜色值,rgba颜色值

2、 如果没有设置背景颜色,那么背景就是透明,默认值:transparent

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>css</title>

<style type="text/css">

div{width:150px;height:60px;line-height:60px;background-color:#00ff00;}

p{width:100px;height:30px;background-color:#ff0000;}

</style>

</head>

<body>

<div>

我要好好学习

<p></p>

</div>

</body>

</html>

p元素会在div元素外面

修改如下

div{width:220px;height:60px;line-height:60px;background-color:#ff0000;position:relative;}

p{width:100px;height:30px;background-color:rgba(0,0,255,0.5);position:absolute;left:0;top:0}

返回值: